package jp.co.ikd.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Check {

	private static final String TIME_STAMP_FORMAT = "yyyyMMddHHmmssSSS";

	public static boolean isTimeStamp(String str) {

		try {
			SimpleDateFormat sdf = new SimpleDateFormat(TIME_STAMP_FORMAT);
			sdf.setLenient(false);
			sdf.parse(str);
			return true;
		} catch (ParseException e) {
			return false;
		}
	}

	public static boolean isDateYMD(String str) {

		return isDate(str, DateUtil.PLANE_YYYYMMDD);
	}

	public static boolean isDateYMDFormat(String str) {

		return isDate(str, DateUtil.FORMATED_YYYYMMDD);

	}

	public static boolean isDate(String str, String pattern) {

		if (str == null || str.length() <= 0) {
			return false;
		}

		try {
			SimpleDateFormat sdf = new SimpleDateFormat(pattern);
			sdf.setLenient(false);
			sdf.parse(str);
			return true;
		} catch (ParseException e) {	
			return false;
		}
	}

	public static boolean isEqual(Date target, Date compare) {
		return target.equals(compare);
	}

	public static boolean isEqual(String targetDate, String compareDate) throws ParseException {

		Date target = DateUtil.toDate(targetDate, DatePattern.FORMATED_YYYYMMDDHH24MISS);
		Date compare = DateUtil.toDate(targetDate, DatePattern.FORMATED_YYYYMMDDHH24MISS);
		return target.equals(compare);
	}

	/** よりおおきいか */
	public static boolean isGraterThan(Date target, Date compare) {

		return target.compareTo(compare) > 0 ? true : false;
	}

	/** 以上か */
	public static boolean isGraterEqual(Date target, Date compare) {

		return target.compareTo(compare) >= 0 ? true : false;
	}

	/** より小さいか */
	public static boolean isLessthan(Date target, Date compare) {

		return target.compareTo(compare) < 0 ? true : false;
	}

	/** 以下か */
	public static boolean isLessEqual(Date target, Date compare) {

		return target.compareTo(compare) <= 0 ? true : false;
	}
}
